import React,{Component}from 'react';
import {Button} from 'antd';
const context = React.createContext();
const Provider = context.Provider;
const Consumer = context.Consumer;

let store = {
    name:'wjk',
    sayHi(){
        console.log('hi',this.name);
    }
};

let WithProvider = Component=>{
    return props => {
        return <Provider value={store}>
            <Component {...props}/>
        </Provider>
    };
};


@WithProvider
class App extends Component {
    shouldComponentUpdate(nextProps,nextState){
        // setState 会导致render方法被调用，非pureComponent会无脑重新渲染
        // pureComponent 在此方法中nextProps内部进行浅比较
        //函数式组件用React.memo方法包装来实现pureComponent
    }
    render(){
        return <Consumer>
            {
                store=>{
                    return <div><Button type='primary' onClick={()=>{store.sayHi()}}>{store.name}</Button></div>
                }
            }
        </Consumer>
    }
}

export default App;